package org.cypress.rtpack.controller;
//处理rtpack_hostname这个表的控制器

import org.cypress.rtpack.common.core.Result;
import org.cypress.rtpack.entity.RtpackHostname;
import org.cypress.rtpack.entity.RtpackQushi;
import org.cypress.rtpack.entity.RtpackQutag;
import org.cypress.rtpack.entity.PointHistory;
import org.cypress.rtpack.entity.SoeSysname;
import org.cypress.rtpack.service.IRtpackQushiService;
import org.cypress.rtpack.service.IRtpackQutagService;
import org.cypress.rtpack.service.IPointHistoryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

@RestController
@RequestMapping("/trend")
@CrossOrigin
public class RtpackQushiController {

    @Autowired
    private IRtpackQushiService rtpackQushiService;

    @Autowired
    private IRtpackQutagService rtpackQutagService;

    @Autowired
    private IPointHistoryService pointHistoryService;

    /**
     * 新增趋势图
     * @param rtpackQushi 趋势图信息
     * @return Result
     */
    @PostMapping("/add")
    public Result addQushi(@RequestBody RtpackQushi rtpackQushi) {
        return rtpackQushiService.addQushi(rtpackQushi);
    }

    /**
     * 删除趋势图
     * @param id 趋势图ID
     * @return Result
     */
    @DeleteMapping("/delete/{id}")
    public Result deleteQushi(@PathVariable String id) {
        return rtpackQushiService.deleteQushi(id);
    }

    /**
     * 更新趋势图
     * @param rtpackQushi 趋势图信息
     * @return Result
     */
    @PutMapping("/update")
    public Result updateQushi(@RequestBody RtpackQushi rtpackQushi) {
        return rtpackQushiService.updateQushi(rtpackQushi);
    }

    /**
     * 获取趋势图列表
     * @return Result
     */
    @GetMapping("/list")
    public Result getQushiList() {
        return rtpackQushiService.getQushiList();
    }

    /**
     * 根据ID获取趋势图详情
     * @param id 趋势图ID
     * @return Result
     */
    @GetMapping("/detail/{id}")
    public Result getQushiById(@PathVariable String id) {
        return rtpackQushiService.getQushiById(id);
    }

    /**
     * 新增趋势标签
     * @param rtpackQutag 趋势标签信息
     * @return Result
     */
    @PostMapping("/tag/add")
    public Result addQutag(@RequestBody RtpackQutag rtpackQutag) {
        return rtpackQutagService.addQutag(rtpackQutag);
    }

    /**
     * 删除趋势标签
     * @param id 趋势标签ID
     * @return Result
     */
    @DeleteMapping("/tag/delete/{id}")
    public Result deleteQutag(@PathVariable String id) {
        return rtpackQutagService.deleteQutag(id);
    }

    /**
     * 根据th删除趋势标签
     * @param th 趋势标签th
     * @return Result
     */
    @DeleteMapping("/tag/delete/th/{th}")
    public Result deleteQutagByth(@PathVariable String th) {
        return rtpackQutagService.deleteQutagByth(th);
    }

    /**
     * 更新趋势标签
     * @param rtpackQutag 趋势标签信息
     * @return Result
     */
    @PutMapping("/tag/update")
    public Result updateQutag(@RequestBody RtpackQutag rtpackQutag) {
        return rtpackQutagService.updateQutag(rtpackQutag);
    }

    /**
     * 获取趋势标签列表
     * @return Result
     */
    @GetMapping("/tag/list")
    public Result getQutagList() {
        return rtpackQutagService.getQutagList();
    }

    /**
     * 根据ID获取趋势标签详情
     * @param id 趋势标签ID
     * @return Result
     */
    @GetMapping("/tag/detail/{id}")
    public Result getQutagById(@PathVariable String id) {
        return rtpackQutagService.getQutagById(id);
    }

    /**
     * 根据描述模糊分页查询点位历史记录，若description为空则查询所有
     * @param description 描述（可选）
     * @param current 当前页
     * @param size 每页大小
     * @return Result
     */
    @GetMapping("/point/page")
    public Result pagePointHistory(@RequestParam(required = false) String description,
                                 @RequestParam(defaultValue = "1") long current,
                                 @RequestParam(defaultValue = "10") long size) {
        return pointHistoryService.pageByDescription(description, current, size);
    }

    /**
     * 根据NodeId查询点位历史记录
     * @param nodeId 节点ID
     * @return Result
     */
    @GetMapping("/point")
    public Result getPointHistoryByNodeId(@RequestParam  String nodeId) {
        return pointHistoryService.getByNodeId(nodeId);
    }
}


